package top.glike.ssl.auto.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.glike.ssl.auto.domain.SslCloudProvider;
import top.glike.ssl.auto.mapper.SslCloudProviderMapper;
import top.glike.ssl.auto.service.ISslCloudProviderService;

import java.util.Date;
import java.util.List;

/**
 * 厂商配置Service业务层处理
 *
 * @author Sophia
 * @date 2025-10-12
 */
@Service
public class SslCloudProviderServiceImpl implements ISslCloudProviderService {
    @Autowired
    private SslCloudProviderMapper sslCloudProviderMapper;

    /**
     * 查询厂商配置
     *
     * @param id 厂商配置主键
     * @return 厂商配置
     */
    @Override
    public SslCloudProvider selectSslCloudProviderById(Long id) {
        return sslCloudProviderMapper.selectSslCloudProviderById(id);
    }

    /**
     * 查询厂商配置列表
     *
     * @param sslCloudProvider 厂商配置
     * @return 厂商配置
     */
    @Override
    public List<SslCloudProvider> selectSslCloudProviderList(SslCloudProvider sslCloudProvider) {
        return sslCloudProviderMapper.selectSslCloudProviderList(sslCloudProvider);
    }

    /**
     * 新增厂商配置
     *
     * @param sslCloudProvider 厂商配置
     * @return 结果
     */
    @Override
    public int insertSslCloudProvider(SslCloudProvider sslCloudProvider) {
        sslCloudProvider.setUpdatedTime(new Date());
        sslCloudProvider.setCreatedTime(sslCloudProvider.getUpdatedTime());
        return sslCloudProviderMapper.insertSslCloudProvider(sslCloudProvider);
    }

    /**
     * 修改厂商配置
     *
     * @param sslCloudProvider 厂商配置
     * @return 结果
     */
    @Override
    public int updateSslCloudProvider(SslCloudProvider sslCloudProvider) {
        sslCloudProvider.setUpdatedTime(new Date());
        return sslCloudProviderMapper.updateSslCloudProvider(sslCloudProvider);
    }

    /**
     * 批量删除厂商配置
     *
     * @param ids 需要删除的厂商配置主键
     * @return 结果
     */
    @Override
    public int deleteSslCloudProviderByIds(Long[] ids) {
        return sslCloudProviderMapper.deleteSslCloudProviderByIds(ids);
    }

    /**
     * 删除厂商配置信息
     *
     * @param id 厂商配置主键
     * @return 结果
     */
    @Override
    public int deleteSslCloudProviderById(Long id) {
        return sslCloudProviderMapper.deleteSslCloudProviderById(id);
    }

    @Override
    public SslCloudProvider saveSslCloudProvider(SslCloudProvider sslCloudProvider) {
        if (sslCloudProvider.getId() != null) {
            sslCloudProvider.setUpdatedTime(new Date());
            sslCloudProviderMapper.updateSslCloudProvider(sslCloudProvider);
        } else {
            sslCloudProvider.setUpdatedTime(new Date());
            sslCloudProvider.setCreatedTime(sslCloudProvider.getUpdatedTime());
            sslCloudProviderMapper.insertSslCloudProvider(sslCloudProvider);
        }
        return sslCloudProvider;
    }
}
